package com.zb.quartz.job;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;

import com.zb.common.utils.Constants;
import com.zb.quartz.TaskMessage;

public class DefaultJob implements Job {

    @Override
    public void execute(JobExecutionContext context) {
        JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
        TaskMessage task = (TaskMessage) jobDataMap.get(Constants.TASK_MESSAGE);
        Class<?> classz = null;
        try {
            classz = Class.forName(task.getTaskClassz());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try {
            Method method = classz.getDeclaredMethod(task.getTaskMethod());
            method.invoke(classz.newInstance());
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }

    }
}
